Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SWRL parsing #654

Merged
merged 1 commit into from
Dec 31, 2023
Merged

Fix SWRL parsing #654

merged 1 commit into from
Dec 31, 2023

Conversation

vChavezB
Copy link
Contributor

@vChavezB vChavezB commented Dec 11, 2023

Addes support for correct xslt transformation for TOC and SWRL display. The transformation checks if rdfs:label is defined if not the rules are generically number as they appear in the XML serialization of the ontology.

Fixes #651

TOC

grafik

Contents

grafik

@vChavezB
Copy link
Contributor Author

vChavezB commented Dec 11, 2023

The only bug I notice is that it seems that the TOC and numbering starting at 3. Cross reference does not match number-wise.

grafik

grafik

@vChavezB
Copy link
Contributor Author

Attached is one of the test ontologies from this repo (turtle) with two rules just to test this PR.

bne.txt

@dgarijo
Copy link
Owner

dgarijo commented Dec 11, 2023

@vChavezB thanks! Can you please merge against the develop branch?
The numbering is generated dynamically based on the anchors you have. Maybe you are introducing a new anchor?

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010-2013, Silvio Peroni <[email protected]>
Copyright (C) 2023, Victor Chavez <[email protected]>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add your copyright under the code extension you have added? Otherwise it may look like you claim the copyright for the whole document, which I don't think it's appropriate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sure, yes it looks misleading. Thanks for the feedback.

@vChavezB
Copy link
Contributor Author

vChavezB commented Dec 11, 2023

@vChavezB thanks! Can you please merge against the develop branch? The numbering is generated dynamically based on the anchors you have. Maybe you are introducing a new anchor?

I think I fixed this bug. Still trying to show the SWRL rules as its own section, it does not appear in the TOC but only in the overview and the contents.

Will update the PR.

@vChavezB vChavezB changed the base branch from master to develop December 11, 2023 14:43
@vChavezB
Copy link
Contributor Author

Changed to develop. TOC and section numbering is correct but the section SWRL Rules in TOC is missing. Do you have any suggestions on what it could be?

@vChavezB
Copy link
Contributor Author

It appears just as

grafik

Without the section number also at the TOC as mentioned in my previous comment.

grafik

@dgarijo
Copy link
Owner

dgarijo commented Dec 11, 2023

I'll have to have a look. Probably a missing id or class.

@dgarijo
Copy link
Owner

dgarijo commented Dec 11, 2023

Thanks for your quick response btw! I am a little overwhelmed this week, but I'd like to add all these changes before the holidays.

@vChavezB
Copy link
Contributor Author

Maybe you are introducing a new anchor?

Is this what you mean by anchor ? This is what I did

https://github.com/vChavezB/Widoco/blob/63c46209082e2e107026905d3e073c79a62a61cd/src/main/java/widoco/LODEParser.java#L286

Reason is that SWRL rules do not have an IRI, this is how they look serialized as xml rdf

  <rdf:Description rdf:about="http://datos.bne.es/vocab/a">
       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Variable"/>
   </rdf:Description>
   <rdf:Description>
       <swrla:isRuleEnabled rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</swrla:isRuleEnabled>
       <rdfs:comment>comment s2</rdfs:comment>
       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Imp"/>
       <swrl:body>
           <rdf:Description>
               <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
               <rdf:first>
                   <rdf:Description>
                       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                       <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1001"/>
                       <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                   </rdf:Description>
               </rdf:first>
               <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
           </rdf:Description>
       </swrl:body>
       <swrl:head>
           <rdf:Description>
               <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
               <rdf:first>
                   <rdf:Description>
                       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                       <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1002"/>
                       <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                   </rdf:Description>
               </rdf:first>
               <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
           </rdf:Description>
       </swrl:head>
   </rdf:Description>
   <rdf:Description>
       <swrla:isRuleEnabled rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</swrla:isRuleEnabled>
       <rdfs:comment>comment s1</rdfs:comment>
       <rdfs:label>S1</rdfs:label>
       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Imp"/>
       <swrl:body>
           <rdf:Description>
               <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
               <rdf:first>
                   <rdf:Description>
                       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                       <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1001"/>
                       <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                   </rdf:Description>
               </rdf:first>
               <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
           </rdf:Description>
       </swrl:body>
       <swrl:head>
           <rdf:Description>
               <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
               <rdf:first>
                   <rdf:Description>
                       <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                       <swrl:classPredicate rdf:resource="http://datos.bne.es/def/C1002"/>
                       <swrl:argument1 rdf:resource="http://datos.bne.es/vocab/a"/>
                   </rdf:Description>
               </rdf:first>
               <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
           </rdf:Description>
       </swrl:head>
   </rdf:Description>

and the xslt html transformation

		<div id="swrlrules">
			<h2>SWRL rules</h2>
			<ul class="hlist"></ul>
			<div id="d4e4498" class="entity">
				<h3>Rule #1 
					<span class="backlink">back to 
						<a href="#toc">ToC</a>
					</span>
				</h3>
				<p>
					<strong>Comment: </strong>comment s2
					<br />
					<br />
					<a href="#d4e4288" title="http://datos.bne.es/def/C1001">Work</a>
					<sup title="class" class="type-c">c</sup>(?) -&gt; 
					<a href="#d4e4316" title="http://datos.bne.es/def/C1002">Expression</a>
					<sup title="class" class="type-c">c</sup>(?)
				</p>
			</div>
			<div id="d4e4554" class="entity">
				<h3>Rule #2
					<span class="backlink">back to 
						<a href="#toc">ToC</a>
					</span>
				</h3>
				<p>
					<strong>Comment: </strong>comment s1
					<br />
					<br />
					<a href="#d4e4288" title="http://datos.bne.es/def/C1001">Work</a>
					<sup title="class" class="type-c">c</sup>(?) -&gt; 
					<a href="#d4e4316" title="http://datos.bne.es/def/C1002">Expression</a>
					<sup title="class" class="type-c">c</sup>(?)
				</p>
			</div>
		</div>

@dgarijo
Copy link
Owner

dgarijo commented Dec 11, 2023

It looks like you are not at fault, I need to review this a little bit in detail @vChavezB. I just need a little time

@vChavezB
Copy link
Contributor Author

Thanks for your quick response btw! I am a little overwhelmed this week, but I'd like to add all these changes before the holidays.

sure no prob!

@dgarijo
Copy link
Owner

dgarijo commented Dec 12, 2023

Sorry, but the tests don't pass. Are you sure you pass them locally? Which version of Java are you using?

@vChavezB
Copy link
Contributor Author

Let me check why they didnt pass.
Btw i found the bug I think it has to do with h2 tag replacement in the LodeParser

@vChavezB vChavezB force-pushed the swrl-parser-xslt branch 2 times, most recently from fc4bdc7 to 8c9838d Compare December 12, 2023 17:36
@vChavezB
Copy link
Contributor Author

I think there was a missing import. Also solved the hyperlink of swrl rule sections. I did not use the language properties and at the moment replace it directly see

https://github.com/vChavezB/Widoco/blob/8c9838d12c1b4b418cda4aea6e9d28a27a419d53/src/main/java/widoco/LODEParser.java#L208

@vChavezB vChavezB force-pushed the swrl-parser-xslt branch 5 times, most recently from c07e58f to ad1d537 Compare December 16, 2023 10:45
@vChavezB
Copy link
Contributor Author

vChavezB commented Dec 16, 2023

I was experimenting with the project AOWLN, a Protégé plugin to generate images from SWRL rules. I modified it to be used independent of protege to try to integrate it with widoco and named it aowln-sa.

I wanted to integrate it in widoco but due to dependency conflicts (owl-api 4.5.25) and my limted experience with java I am using it separately by generating the images and then modifying the cross-ref-xx.html section. However sometimes if the SWRL graph is small then the ratio of images looks different. Do you have any suggestions on how to achieve a more proportionate ratio ? I am not that good at css,html and javascript for websites. This is my css and this is an example of how I attach the images to the cross-ref-xx.hml page.

<div class="grid-container">
    <div class="swrl-container">Body
    <img src="swrlrules/rule_R3_AOs_are_transitive_from_device_profile-body.png" style="width: 350px; display: inline-block;" title="SWRL Body">
    </div>
    <div class="swrl-container">Head<img src="swrlrules/rule_R3_AOs_are_transitive_from_device_profile-head.png" style="width: 350px; display: inline-block;" title="SWRL Head">
    </div>
</div>

Big graph

Small graph

@vChavezB
Copy link
Contributor Author

After some chat gpt and debugging I have made a javascript to scale the swrl images so they have the same ratio.

grafik

This is not part of the PR but just wanted to give some ideas on how this might look integrated into Widoco :)

@dgarijo
Copy link
Owner

dgarijo commented Dec 18, 2023

@vChavezB thanks for your edits. I guess that if you want to add images for rules, we can introduce a metadata property for annotating them in the ontology, so you don't need to add them manually. Something like widoco:hasRuleImage, or something like that. I am bringing this up in case this helps things.
Are you done with your edits? I see that you are still committing to this PR.

@vChavezB
Copy link
Contributor Author

Yes, you can do a review now.

About the metadata... Im afk so I will post later some feedback about it.

@vChavezB
Copy link
Contributor Author

vChavezB commented Dec 19, 2023

Hello @dgarijo

we can introduce a metadata property for annotating them in the ontology

Would you annotate this for each rule? If yes, I do not know if this would work for my use case (i.e. Protege). In protege you can define SWRL rules over the SWRL Tab. As far as I know you can add a name (rdfs:label) and a comment (rdfs:comment). You would need to manually add the widoco:hasRuleImage annotation in the serialized representation of the ontology outside of Protege.

grafik

Addes support for correct xslt transformation
for TOC and SWRL display. The transformation checks
if rdfs:label is defined if not the rules are generically
number as they appear in the XML serialization of the ontology.
@dgarijo dgarijo merged commit 95387b0 into dgarijo:develop Dec 31, 2023
4 checks passed
@dgarijo
Copy link
Owner

dgarijo commented Dec 31, 2023

Thanks, I opened a new issue #662 to follow up on this. Merging this PR (about time!)

@dgarijo dgarijo mentioned this pull request Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SWRL rules dont appear.
2 participants